package com.jic.product.model.vo.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MStoreBaseResponse<T> implements Serializable {

    private static final long serialVersionUID = 3523558943791146781L;
    private static final String SUCCESS_CODE = "0000";
    private static final String SUCCESS_MESSAGE = "调用成功";

    /**
     * 返回编码,0000为成功,其他为失败;
     */
    private String code;

    /**
     * 返回信息;
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;




    public static MStoreBaseResponse error(String code, String message) {
        return MStoreBaseResponse.builder()
                .code(code)
                .msg(message)
                .build();
    }

    public static <T> MStoreBaseResponse<T> success(T data) {
        return MStoreBaseResponse.<T>builder()
                .code(SUCCESS_CODE)
                .msg(SUCCESS_MESSAGE)
                .data(data)
                .build();
    }

    public static boolean checkIsSuccess(MStoreBaseResponse MStoreBaseResponse) {
        if (MStoreBaseResponse != null && SUCCESS_CODE.equals(MStoreBaseResponse.getCode())) {
            return true;
        }
        return false;
    }

}
